package org.kjk;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class JSon extends AbstractController {

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest requ,
			HttpServletResponse resp) throws Exception {
		JSONObject jObj = new JSONObject();
		JSONArray arrayObj = new JSONArray();
		try {
			jObj.put("users", arrayObj);
			for (int i = 1; i <= 6; i++) {
				JSONObject obj1 = new JSONObject();
				obj1.put("id", i);
				obj1.put("firstName", "data" + i + "-1");
				obj1.put("lastName", "data" + i + "-2");
				arrayObj.put(obj1);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		PrintWriter out = resp.getWriter();
		out.println(jObj);
		out.flush();
		out.close();
		return null;
	}

}
